package com.woniu.controller;


import com.woniu.entity.User;
import com.woniu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("user")
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping("/findAll")
    public ResponseEntity findAll(){
        List<User> all = userService.findAll();
        return ResponseEntity.ok(all);
    }
    @GetMapping("/{username}")
    public ResponseEntity getUserByUsername(@PathVariable(value = "username") String username){
        User user = userService.findUserByUsername(username);
        return ResponseEntity.ok(user);
    }
    @PutMapping("/")
    public ResponseEntity updateUser(@RequestBody User user){
        int i = userService.updateOne(user);
        return ResponseEntity.ok(i);
    }
}
